package com.example.helloapplication;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private static String tag = "start_activity";

    private Button messageButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d(tag,"main_activity");
        messageButton = findViewById(R.id.click_button);
        messageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              /*  Toast.makeText(MainActivity.this,"This is a message",Toast.LENGTH_SHORT)
                .show();*/
            //  finish();

               /* Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("http://www.baidu.com"));*/
              //  intent.addCategory("com.example.MYAPPLICATION");

                Intent intent = new Intent(MainActivity.this,OtherActivity.class);
                intent.putExtra("extra_data","Hello SecondActivity");
                startActivityForResult(intent,1);
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
       super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 1 && resultCode == RESULT_OK){
            Log.d("main_activity_result",String.valueOf(data.getIntExtra("resultData",0)));
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_test,menu);

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        switch (item.getItemId()){
            case R.id.addItem:
                Toast.makeText(MainActivity.this,"addItem",Toast.LENGTH_SHORT)
                .show();
                break;
            case R.id.removeItem:
                Toast.makeText(MainActivity.this,"removeItem",Toast.LENGTH_SHORT)
                .show();
            default:
                break;
        }

        return super.onOptionsItemSelected(item);
    }
}
